#pragma once
#include "RBTree.hpp"

namespace lw
{
	template<class K, class V, class Compare = std::less<K>>
	class map
	{
		struct MapKOfT
		{
			const K& operator()(const std::pair<K, V>& kv)
			{
				return kv.first;
			}
		};
	public:
		typedef typename RBTree<K, std::pair<const K, V>, MapKOfT, Compare>::iterator iterator;
		typedef typename RBTree<K, std::pair<const K, V>, MapKOfT, Compare>::const_iterator const_iterator;

		iterator begin()
		{
			return _rbt.begin();
		}
		iterator end()
		{
			return _rbt.end();
		}
		const_iterator begin() const
		{
			return _rbt.begin();
		}
		const_iterator end() const
		{
			return _rbt.end();
		}
		std::pair<iterator, bool> insert(const std::pair<K, V>& val)
		{
			return _rbt.Insert(val);
		}
		iterator find(const K& key)
		{
			return _rbt.Find(key);
		}
		V& operator[](const K& key)
		{
			std::pair<iterator, bool> ret = insert(std::make_pair(key, V()));
			return ret.first->second;
		}
		map()
		{}
		~map()
		{}
	private:
		RBTree<K, std::pair<const K, V>, MapKOfT, Compare> _rbt;
	};
}